using UnityEngine;
using System.Collections;

public class MoveZ : MonoBehaviour {
	
	public float z1 = 0f;
	public float z2 = 0f;
	public float speed = 0.2f;
	
	bool toUp = true;

	
	// Update is called once per frame
	void Update () {
		
		Vector3 temp = transform.position;
		if(temp.z >= z1)
		{
			toUp = false;
		}
		if(temp.z <= z2)
		{
			toUp = true;
		}
		
		if(toUp)
		{
			temp.z += speed*(Time.deltaTime);
			transform.position = temp;
		}
		else
		{
			temp.z -= speed*(Time.deltaTime);
			transform.position = temp;
		}
	}
}